package com.example.blog.service;

import com.example.blog.mapper.BlogMapper;
import com.example.blog.mapper.UserInfoMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;
    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);

    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if(blogInfo==null&&blogInfo.getUserId()<=0){
            return null;

        }
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return  userInfo;
    }

//    public Integer setUserInfo(UserInfo userInfo) {
//        return userInfoMapper.insertUserInfo(userInfo);
//
//    }
     public Integer setUserInfo(String username,String password) {
          return userInfoMapper.insertUserInfo(username,password);

     }
}
